//
//  DKBankSelectView.m
//  DanKU
//
//  Created by 吴斌 on 2023/12/6.
//

#import "DKBankSelectView.h"
#import "DKBankTableCell.h"
@interface DKBankSelectView()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong)UITableView * dk_BankSelectTableView;
@end
@implementation DKBankSelectView
-(instancetype)init{
    if(self = [super init]){
        self.backgroundColor = DK_Hex(@"#F7F7F8");
        self.layer.cornerRadius = DK_IsWidthScale(14);
        self.clipsToBounds = YES;
        [self dk_addSubView];
    }
    return self;
}
- (void)dk_addSubView{
    self.dk_BankSelectTableView = [[UITableView alloc] init];
    self.dk_BankSelectTableView.backgroundColor = UIColor.clearColor;
    self.dk_BankSelectTableView.delegate = self;
    self.dk_BankSelectTableView.dataSource = self;
    self.dk_BankSelectTableView.estimatedRowHeight = 0;
    self.dk_BankSelectTableView.estimatedSectionHeaderHeight = 0;
    self.dk_BankSelectTableView.estimatedSectionFooterHeight = 0;
    self.dk_BankSelectTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.dk_BankSelectTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    self.dk_BankSelectTableView.showsVerticalScrollIndicator = NO;
    self.dk_BankSelectTableView.shouldIgnoreScrollingAdjustment = YES;
    self.dk_BankSelectTableView.shouldRestoreScrollViewContentOffset = YES;
    [self addSubview:self.dk_BankSelectTableView];
    [self.dk_BankSelectTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(@(DK_IsWidthScale(0)));
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.bottom.equalTo(@(DK_IsWidthScale(0)));
    }];
}
-(void)setBankSelects:(NSArray *)bankSelects{
    _bankSelects = bankSelects;
    [self.dk_BankSelectTableView reloadData];
}
#pragma mark -- UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.bankSelects.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return DK_IsWidthScale(40);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DKBankTableCell *dk_BankTableCell = [DKBankTableCell bankTableCell:tableView];
    dk_BankTableCell.bankName = self.bankSelects[indexPath.row];
    return dk_BankTableCell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(self.BankSelectScuessBlock){
        self.BankSelectScuessBlock(self.bankSelects[indexPath.row]);
    }
}

@end
